﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace SLMapviewer3.Web
{
    public partial class _Default : System.Web.UI.Page
    {
        protected string InitParams { get; private set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            // Get the UI culture
            System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentUICulture;

            // Mapfile to use
            string mapfile = System.Configuration.ConfigurationManager.AppSettings["mapfile"];
            Session["mapfile"] = mapfile;
            
            
            // Textbox to be used to receive responses
            // from the silverlight control. 
            // This control MUST EXIST IN THE ASPX PAGE
            string sTargetControlID = "txtBox1";

            // Textbox to be used to send map request to
            // the silverlight control. 
            // This control MUST EXIST IN THE ASPX PAGE
            string sRequestControlID = "TextBox1";

            // Application path
            string appPath = Request.ApplicationPath;

            // Make sure the base url sent to the silverlight control is correct.
            // Otherwise you get the "the remote server returned an error: not found"
            // when trying to do the async request to xml.aspx

            if (appPath == "/") { appPath = string.Empty; }
            //string baseUrl = Request.Url.GetLeftPart(UriPartial.Authority) + appPath;
            string baseUrl = System.Configuration.ConfigurationManager.AppSettings["XMLUrl"];

            // Whether the legend will appear inside or next to the map window
            // 1 will make the legend appear inside the map
            string strInternalControls = "1";



            // Display debug window or not
            string sDebug = "0";

            // Mode ('NORMAL' or 'KIOSK')
            // If set to KIOSK map control will display a limited number
            // of buttons. Useful if the app is running through an interactive kiosk
            string sMode = System.Configuration.ConfigurationManager.AppSettings["UIMode"];

            InitParams = string.Format(@"MapServiceUrl={0},Width={1},Height={2}
                                        ,InternalControls={3}
                                        ,DebugOn={4}
                                        ,Culture={5}
                                        ,TargetControlID={6}
                                        ,RequestControlID={7}
                                        ,SessionID={8}
                                        ,Mode={9}
                                        ,Mapfile={10}"
                                     , baseUrl + "/xml.aspx"
                                     , System.Configuration.ConfigurationManager.AppSettings["mapwidth"]
                                     , System.Configuration.ConfigurationManager.AppSettings["mapheight"]
                                     , strInternalControls
                                     , sDebug
                                     , ci.Name
                                     , sTargetControlID
                                     , sRequestControlID
                                     , string.Empty
                                     , sMode
                                     , System.Configuration.ConfigurationManager.AppSettings["mapfile"].ToString());


        }

       
        
    }
}
